home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12688 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Statistically Random Number algorithm
  5. Date: 20 Mar 1996 15:48:19 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4iq5g3INN17g@keats.ugrad.cs.ubc.ca>
  8. References: <314D0B67.3C16@psu.edu> <4ikle5$1rf@sparcserver.lrz-muenchen.de>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4ikle5$1rf@sparcserver.lrz-muenchen.de>,
  12. Kurt Watzka <watzka@stat.uni-muenchen.de> wrote:
  13.  >"Jason A. Soloff" <jas251@psu.edu> writes:
  14.  >
  15.  >>I am working on a monte carlo simulation program to model some problems 
  16.  >>in astronomy.  One thing I am running into, however, is the problem of 
  17.  >>the pseudo-random number tables.  Does anyone have an algorithm (or 
  18.  >>code) for a truly statistically random number generator?
  19.  >
  20.  >A guy from NASA once suggested that it is really simple. All you need
  21.  >is a satelite that records the background radiation. You digitize 
  22.  >that and have a perfectly random sequence of random numbers.
  23.  
  24. I just wrote code this morning that uses /dev/audio on a Sun box to produce a
  25. 256 byte state array for the random() function. What I do is take the least
  26. significant bit from each byte of a block of 2048 read from the audio device.
  27. I XOR these bits into a 256 byte block that is initially zero, lather, rinse
  28. and repeat 32 times to produce a final block. Even with the mike unplugged,
  29. there is enough variation in the samples that I can get a decent random block
  30. this way.
  31.  
  32. In production, the microphone will be strategically placed next to a fan.
  33.  
  34. You don't really need cosmic background radiation---just good old noise should
  35. do the trick.
  36.  
  37.  >The word algorithm implies a _deterministic_ process, and there
  38.  >cannot be a deterministic process that produces _random_ output.
  39.  
  40. Right. Even with the above /dev/audio method, the sequence is completely
  41. determined once you create the 256 byte vector. However, what you can do is
  42. periodically update the state array with new bits read from the device.
  43. -- 
  44.  
  45.